import React, { Component } from 'react'
import './index.css';

export default class Footer extends Component {
    render() {
        //获取所有的任务
        let {todos} = this.props;
        let complete = todos.filter(item => item.done);
        return (
            <div className="todo-footer">
                <label>
                    <input checked={todos.length === complete.length && todos.length > 0} type="checkbox" onChange={this.checkAll} />
                </label>
                <span> <span>已完成 {complete.length}</span> / 全部 {todos.length} </span>
                <button className="btn btn-danger" onClick={this.clearDoneTodo}>清除已完成任务</button>
            </div>
        )
    }

    checkAll = (e) => {
        //调用 props 中的方法
        this.props.checkAllTodo(e.target.checked);
    }

    //删除已经完成的任务
    clearDoneTodo = () => {
        this.props.removeDoneTodo();
    }   
}
